home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NUMBERS.SWG / 0018_REVERSE.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  770b  |  28 lines

  1. {
  2.  a problem.  I am asked to find the reverse of a positive Integer.  For
  3.  example the reverse of 123 is 321 or the reverse of 1331 is 1331.
  4.  My teacher said that we should use div and MOD.
  5. }
  6.  
  7. Var
  8.   X, Y: Integer;
  9.  
  10. begin
  11.   X := PositiveInteger;
  12.   Y := 0;
  13.  
  14.   While X > 0 do
  15.   begin
  16.     Y := (Y * 10) + (X mod 10);
  17.     X := X div 10;
  18.   end;
  19.  
  20. {
  21. The result will be in Y.  Just so you do learn something of use out of this: It
  22. is a fact that the difference between two transposed (reversed) numbers will be
  23. evenly divisible by 9. This can be of help if you are doing something
  24. accounting related and are trying to figure out why your numbers don't jive. if
  25. the amount you are out is evenly divisible by 9, it is most likely a
  26. transposing error.
  27. }
  28.